package xiegd.study.redis;

import cn.hutool.json.JSONUtil;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import java.util.HashMap;
import java.util.Map;

/**
 * @Description:
 * @Author: xieguangda
 * @Date: 2021年06月28日 13:47
 */
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(classes = {RedisConfig.class})
public class RedisStudy {

    @Autowired
    private RedisUtil redisUtil;

    @Autowired
    private RedisTemplate<String, Object> redisTemplate;

    @Test
    public void test(){
        Map<String, Object> hashMap = new HashMap<String, Object>();
        hashMap.put("123", "hello");
        hashMap.put("abc", "456");

        redisUtil.hmset("hashTT", hashMap);
        System.out.println(redisUtil.hmget("hashTT"));

        redisUtil.set("a","1235555555555");
        System.out.println(redisUtil.get("a"));

        // redisTemplate.opsForList().rightPush(RedisKeyConstant.MOON_HOUSE_KAFKA_PROVIDOR_ERROR_DATA, JSONUtil.parseObj(map));

    }

    @Test
    public void test2(){
        Map<String, Object> hashMap = new HashMap<String, Object>();

        hashMap.put("xiegdtest1422122", "我是测试22");
        hashMap.put("xiegdtest2422133", "45633");

        redisTemplate.opsForList().rightPush("mh:crm:moonhouse:kafka:providor:error", JSONUtil.parseObj(hashMap));

       // System.out.println(redisTemplate.getExpire("mh:crm:moonhouse:kafka:providor:error"));
       // System.out.println(redisTemplate.opsForValue().get("mh:crm:moonhouse:kafka:providor:error"));

       // System.out.println(redisTemplate.opsForHash().get("mh:crm:moonhouse:kafka:providor:error","xieguangda1"));
       // System.out.println(redisTemplate.opsForList().index("mh:crm:moonhouse:kafka:providor:error", 1));
       // redisTemplate.opsForValue().set("jfodiafjaifjaiofj","xiexie");
     //   System.out.println(redisTemplate.randomKey());;
       // System.out.println(redisTemplate.opsForValue().get("jfodiafjaifjaiofj"));

        //redisTemplate.opsForHash().put("test:001a:gd",hashMap);
        redisTemplate.opsForHash().putAll("test:001a:gd11222",hashMap);
    }


    @Test
    public void jedisSet(){

    }
}
